﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class WUFangBZControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        TextBox 房源说明备注;
        Button btnInsert;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            房源说明备注 = (TextBox)FindControl("房源说明备注");
            btnInsert = (Button)FindControl("btnInsert");
            btnInsert.Click += new EventHandler(btnInsert_Click);
            base.OnLoad(e);
            if (!base.Page.IsPostBack) 
            {
                Bind();
            }
            IsLookPerson();
        }
        

         private void IsLookPerson()
        {
            string sql = "Select rolename from zs_role where id in (Select roleid from zs_user_in_role where userid = '"+userid+"')";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            if (dt.Rows.Count >0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["rolename"].ToString().Equals("查看人员"))
                    {
                        Button btnInsert = (Button)FindControl("btnInsert");
                        btnInsert.Visible = false;
                    }
                }
            }
        }

        protected void Bind()
        {
            string strId = base.Page.Request["ID"];
            if (!string.IsNullOrEmpty(strId)) {
                string sql = "select 房源说明备注 from zs_project where id='" + strId + "'";
                房源说明备注.Text = _EluZSDataProvider.GetString(sql);
            }
        }
        protected void btnInsert_Click(object sender, EventArgs e)
        {
            string strId = base.Page.Request["ID"];
            if (!string.IsNullOrEmpty(strId)) {
                string sql = "update zs_project set 房源说明备注='" + 房源说明备注.Text.Trim() + "' where id='" + strId + "'";
                _EluZSDataProvider.RunSqlNon(sql);
                base.Page.ClientScript.RegisterStartupScript(this.GetType(), "be", "<script>alert('保存成功！');window.close();</script>");
            }
        }
    }
}


